/****************************************************************************
**
**	File Name   : ObjInfoDlg.h
**
**	Project     : DatChecker
**
**	Last Updated: $Header: /DatChecker.root/DatChecker/ObjInfoDlg.h 3     1/20/04 12:08p Neusel $
**
**	Description : 
**
**		CObjInfoDlg class interface and implementation.
**
****************************************************************************/
#ifndef	H_OBJINFODLG
	#define H_OBJINFODLG	__TIMESTAMP__

#if defined(_MSC_VER) && (_MSC_VER >= 1020)
#	pragma once
#endif

#include "MD5.h"

extern Options			theOptions;

class CObjInfoDlg :	public CDialogImpl<CObjInfoDlg>,
					public CDialogResize<CObjInfoDlg>
	{
public:
	enum { IDD = IDD_OBJINFO };
protected:
	CFont				m_font;
	ObjInfo const &		m_objInfo;

	void				setText(int id, LPCTSTR pstr)
							{
							CWindow wnd = GetDlgItem(id);
							
							if (wnd.IsWindow())
								{
								wnd.SetFont(m_font);
								wnd.SetWindowText(pstr);
								}
							}
public:
						CObjInfoDlg(ObjInfo const & objInfo) : m_objInfo(objInfo)
							{ /* Stub CTOR */ }
/*
**	ATL/WTL VooDoo Code	
*/
protected:
	LRESULT				onInitDialog(HWND, LPARAM)
		{
		LOGFONT		lf;
		CDC			dc;
		CString		str;
		CWindow		wnd;

		DlgResize_Init();
		PlaceWindow(*this, theOptions.rObjInfoDlg);
		
 		dc.CreateCompatibleDC();
		::ZeroMemory(&lf, sizeof(LOGFONT));
		lf.lfPitchAndFamily = FF_MODERN;
		lf.lfHeight = -::MulDiv(9, dc.GetDeviceCaps(LOGPIXELSY), 72);
		lf.lfWeight	= FW_BOLD;
		m_font.CreateFontIndirect(&lf);
		//
		//	File name
		//
		setText(IDC_FILE_NAME, m_objInfo.szFile);
		//
		//	File size
		//
		str = StrByteCount(m_objInfo.sFileLen);
		if ((m_objInfo.sDataLen + sizeof(SV6ObjHeader)) > m_objInfo.sFileLen)
			{
			long	lRatio;
			
			lRatio = MulDiv(100, m_objInfo.sFileLen, m_objInfo.sDataLen);
			if (lRatio > 0 && lRatio < 100)
				str.Format(_T("%s Compressed: %ld%%"), StrByteCount(m_objInfo.sFileLen), lRatio);
			}
			
		setText(IDC_FILE_SIZE, LPCTSTR(str));
		//
		//	File dates
		//
		HRESULT		hr;
		CAtlFile	file;
		FILETIME	ftCreated, ftIgnored, ftModified;
			
		hr = file.Create(m_objInfo.szFile, GENERIC_READ, 0, OPEN_EXISTING);
		if (SUCCEEDED(hr) &&
			GetFileTime(file, &ftCreated, &ftIgnored, &ftModified))
			{
		    setText(IDC_FILE_CREATED, StrFileTime(ftCreated));
		    setText(IDC_FILE_TOUCHED, StrFileTime(ftModified));
			}
		else
			{
			setText(IDC_FILE_CREATED, kStrEmpty);
			setText(IDC_FILE_TOUCHED, kStrEmpty);
			}
					
		file.Close();
		//
		//	CRC
		//
		str.Format(_T("0x%08lX"), m_objInfo.dwCRC);
		setText(IDC_DATA_CRC, LPCTSTR(str));
		//
		//	Image Count
		//
		setText(IDC_IMG_COUNT, StrNum(m_objInfo.nImages));
		//
		//	String Table
		//
		setText(IDC_STRING_TABLE, m_objInfo.szStrings);
		
		return TRUE;
		}

	LRESULT				onCommand(WORD, WORD wID, HWND, BOOL &)
							{
							(void) GetWindowRect(&theOptions.rObjInfoDlg);
							EndDialog(wID);
							return 0;
							}
public:
	BEGIN_DLGRESIZE_MAP(CObjInfoDlg)
		DLGRESIZE_CONTROL(IDC_FILE_NAME, DLSZ_SIZE_X)
		DLGRESIZE_CONTROL(IDC_FILE_SIZE, DLSZ_SIZE_X)
		DLGRESIZE_CONTROL(IDC_FILE_CREATED, DLSZ_SIZE_X)
		DLGRESIZE_CONTROL(IDC_FILE_TOUCHED, DLSZ_SIZE_X)
		DLGRESIZE_CONTROL(IDC_DATA_CRC, DLSZ_SIZE_X)
		DLGRESIZE_CONTROL(IDC_IMG_COUNT, DLSZ_MOVE_X)
		DLGRESIZE_CONTROL(IDC_IMG_COUNT_LBL, DLSZ_MOVE_X)
		DLGRESIZE_CONTROL(IDC_STRING_TABLE, DLSZ_SIZE_X|DLSZ_SIZE_Y)
	END_DLGRESIZE_MAP()

	BEGIN_MSG_MAP_EX(CObjInfoDlg)
		MSG_WM_INITDIALOG(onInitDialog)

		COMMAND_ID_HANDLER(IDOK, onCommand)
		COMMAND_ID_HANDLER(IDCANCEL, onCommand)
		
		CHAIN_MSG_MAP(CDialogResize<CObjInfoDlg>)
	END_MSG_MAP()
	};
#endif	// H_OBJINFODLG
/****************************************************************************
**
**	$History: ObjInfoDlg.h $
 * 
 * *****************  Version 3  *****************
 * User: Neusel       Date: 1/20/04    Time: 12:08p
 * Updated in $/DatChecker.root/DatChecker
 * v1.7 -- rearranged Properties dialog and added yellow flags.
 * 
 * *****************  Version 2  *****************
 * User: Neusel       Date: 1/20/04    Time: 9:18a
 * Updated in $/DatChecker.root/DatChecker
 * v1.7 -- Added "Image Count" field to properties dialog.
 * 
 * *****************  Version 1  *****************
 * User: Neusel       Date: 8/14/03    Time: 9:25a
 * Created in $/DatChecker.root/DatChecker
**
**	-------------------------------------------------------------------------
**
**	End of ObjInfoDlg.h
**
****************************************************************************/
